<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>个人主页</title>
    <link type="text/css" rel="stylesheet" href="/static/css/myCenter.css">
    <script type="text/javascript" src="/static/js/jquery-3.4.1.js"></script>
</head>
<body>
<div class="u-main">
    <jsp:include page="head.jsp"></jsp:include>
    <div class="u-top">
        <div class="u-myself">
            <div class="left">
                <div class="img">
                    <div>

                        <a href="#" class="tou-xiang"><img src="${user.userPhoto}"/></a>

                    </div>
                </div>
            </div>
            <div class="right">
                <div class="zuo">
                    <div>
                        <p class="p1">
                            <span class="span-1">${user.userName}</span>
                        </p>
                        <p class="p2">
                            <span class="span-2">居住地</span>
                            <span class="span-2-2">${user.userAddress}</span>
                        </p>
                        <p class="p3">
                            <span class="span-3">个人简介</span>
                            <span class="span">${user.userIntro}</span>
                        </p>
                        <p class="p4">
                            <span class="span-4">电子邮件</span>
                            <span class="span">${user.userEmail}</span>
                        </p>
                    </div>
                </div>
                <div class="you">
                    <div>
                        <a href="#" class="p-tc">编辑个人资料</a>
                    </div>
                </div>
            </div>
        </div>

        <div class="u-botton">
            <div class="u-tiezi">
                <a href="myself/mycenter.jsp#" class="f-tc">
                    <div>
                        <span>发帖</span>
                    </div>
                </a>
            </div>
            <c:forEach items="${userPosts}" var="post">
                <div class="u-suibi">
                    <div class="shang-1">
                        <span class="span-1" id="postTitle">${post.postTitle}</span>
                    </div>
                    <div class="shang-2">
                        <span class="span-2">${post.postCreateTime}</span>
                    </div>
                    <div class="zhong">
                        <span>${post.postContent}</span>
                    </div>
                    <div class="img">
                        <img alt="" src="${post.postPhoto}"/>
                    </div>
                    <div class="xia">
                        <form>
                            <input type="hidden" name="postId" value="${post.postId}">
                            <input type="button" class="shanchu" value="删除">
                        </form>
                    </div>
                </div>
                <hr class="f-hr"/>
                <br>
            </c:forEach>
        </div>
    </div>
</div>
<!--------------------- 删除确认 --------------------->
<script>
    $('.shanchu').click(function () {
        const msg = "您真的确定要删除吗？\n\n删除后不能复原！";
        if (confirm(msg) == true) {
            $.ajax({
                url: '/postDelete',
                method: 'get',
                data: $(this).parent().serialize(),
                success: function (data) {
                    alert(data)
                    if (data == "删除帖子成功") {
                        getUsers()
                    }
                },
                error: function () {
                    alert("请求出错")
                }
            })
        }
    });
</script>
<!--------------------- 删除确认-end --------------------->

<!--------------------- 编辑个人信息 --------------------->
<jsp:include page="edit.jsp"></jsp:include>
<!--------------------- 编辑个人信息-end --------------------->

<!--------------------- 上传头像-end --------------------->
<jsp:include page="userPhotoUpload.jsp"></jsp:include>
<!--------------------- 上传头像-end --------------------->

</body>
</html>